#pragma once

#include "ModelessDialog.h"
#include "PairTradeDataModel.h"


class PairCalculatorMain : public CModelessDialog, public L_Observer //public CDialog
{
	DECLARE_DYNAMIC(PairCalculatorMain)

public:
	PairCalculatorMain(CWnd* pParent = NULL);   // standard constructor
	virtual ~PairCalculatorMain();
	
	virtual BOOL Create(CWnd *pParentWnd = CWnd::FromHandle(L_GetMainWnd()));

	virtual BOOL OnInitDialog();
	
// Dialog Data
	enum { IDD = IDD_PAIRCALC_MAIN };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()

protected:
// L_Observer
	virtual void HandleMessage(L_Message const *pMsg);
public:
	void GetLivePrice();
	void GetLivePriceOLD();
	void FillGrid();
	PairTrade SelectedPairTrade;
private:
	CListCtrl m_PairDataListCtrl;
	PairTradeDataModel m_DataModel;
	void InitializeDataCtrlRows();
	CString GetCellText(int row, int col);
	void ResizeControls();
	//data
	
	//helper functions
	void SendOrders();
	bool isFormClosing;
	L_Account *account;
	void CreateSummary(Trade *trade);
	void DeleteSummary(Trade *trade);
	bool bSortStatusAscend;
	bool bSortSymbol1Ascend;
	bool bSortSymbol2Ascend;
	bool bHeaderClickedStart;
	static bool DataSortPredicateAscending(const PairTrade &d1, const PairTrade &d2);
	static bool DataSortPredicateDescending(const PairTrade &d1, const PairTrade &d2);
	static bool Symbol1SortPredicateAscending(const PairTrade &d1, const PairTrade &d2);
	static bool Symbol1SortPredicateDescending(const PairTrade &d1, const PairTrade &d2);
	static bool Symbol2SortPredicateAscending(const PairTrade &d1, const PairTrade &d2);
	static bool Symbol2SortPredicateDescending(const PairTrade &d1, const PairTrade &d2);

public:
	afx_msg void OnBnClickedPairNew();
	afx_msg void OnBnClickedPairOpen();
	afx_msg void OnBnClickedPairDelete();
	afx_msg void OnBnClickedOk();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnClose();
	afx_msg void OnBnClickedPairCoppy();
	afx_msg void OnBnClickedPairSelectall();
	afx_msg void OnBnClickedPairDeselectall();
	afx_msg void OnBnClickedPairClear();
	afx_msg void OnBnClickedPairActivate();
	afx_msg void OnBnClickedPairDeactivate();
	afx_msg void OnCustomdrawList(NMHDR*, LRESULT*);
	afx_msg void OnHeaderClick(NMHDR *pNMHDR, LRESULT *pResult);
};


class DumpClass
{
public:
	CString Comparison;
	double RequiredSpred;
	bool Evalution;
	double RealizedSpread;
	CString PairSize;
	char Nature;
	double Ratio;
	bool IsActive;
	bool IsExecuted;

	int BuyTradeQty;
	double BuyTradePrice;
	double BuyTradeCash;
	CString BuyTradePriceOn;
	CString BuyTradeOrderPriceOn;
	CString BuyTradeOrderDestination;
	CString BuyTradeStockName;
	double BuyTradeStockOpen;
	double BuyTradeStockLow;
	double BuyTradeStockHigh;
	double BuyTradeStockClose;
	double BuyTradeStockBid;
	double BuyTradeStockAsk;
	double BuyTradeStockRatio;
	
	int SellTradeQty;
	double SellTradePrice;
	double SellTradeCash;
	CString SellTradePriceOn;
	CString SellTradeOrderPriceOn;
	CString SellTradeOrderDestination;
	CString SellTradeStockName;
	double SellTradeStockOpen;
	double SellTradeStockLow;
	double SellTradeStockHigh;
	double SellTradeStockClose;
	double SellTradeStockBid;
	double SellTradeStockAsk;
	double SellTradeStockRatio;

public:
	DumpClass()
	{
		Comparison = "";
		RequiredSpred = 0;
		Evalution = false;
		RealizedSpread = 0;
		PairSize = "";
		Nature = 'B';
		Ratio = 0;
		IsActive = false;
		IsExecuted = false;

		BuyTradeQty = 0;
		BuyTradePrice = 0;
		BuyTradeCash = 0;
		BuyTradePriceOn = "";
		BuyTradeOrderPriceOn = "";
		BuyTradeOrderDestination = "";
		BuyTradeStockName = "";
		BuyTradeStockOpen  = 0;
		BuyTradeStockLow = 0;
		BuyTradeStockHigh = 0;
		BuyTradeStockClose = 0;
		BuyTradeStockBid = 0;
		BuyTradeStockAsk = 0;
		BuyTradeStockRatio = 0;
	
		SellTradeQty = 0;
		SellTradePrice = 0;
		SellTradeCash = 0;
		SellTradePriceOn = "";
		SellTradeOrderPriceOn = "";
		SellTradeOrderDestination = "";
		SellTradeStockName = "";
		SellTradeStockOpen = 0;
		SellTradeStockLow = 0;
		SellTradeStockHigh = 0;
		SellTradeStockClose = 0;
		SellTradeStockBid = 0;
		SellTradeStockAsk = 0;
		SellTradeStockRatio = 0;
	}
};